package com.fanjun.learning.multithread.Thread_Specific_Storage_Pattern;

/**
 * Created by fanjun on 16/10/17.
 */
public class Log {
    private static final ThreadLocal tsLogCollection = new ThreadLocal();

    public static void printLog(String s){
        getTSLog().printLog(s);
    }

    public static void close(){
        getTSLog().close();
    }

    private static TSLog getTSLog() {
        TSLog tslog = (TSLog) tsLogCollection.get();
        if (tslog == null){
            tslog = new TSLog(Thread.currentThread().getName() + "-log.txt");
            tsLogCollection.set(tslog);
        }

        return tslog;
    }
}
